/**
 * 
 */
package com.qachecklist.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qachecklist.domain.Check;
import com.qachecklist.domain.Environment;
import com.qachecklist.domain.Item;
import com.qachecklist.domain.PersistableDomain;

/**
 * @author hirokiterashima
 *
 */
public class CheckController extends DomainController {

	private static final long serialVersionUID = 1L;
	
	protected String homePath = "check";
	
	protected String attributeName = "check";
	
	protected String listAttributeName = "checks";

	/**
	 * @see com.qachecklist.web.DomainController#getHomePath()
	 */
	@Override
	protected String getHomePath() {
		return homePath;
	}

	/**
	 * @see com.qachecklist.web.DomainController#getObjectAttributeName()
	 */
	@Override
	protected String getObjectAttributeName() {
		return attributeName;
	}

	/**
	 * @see com.qachecklist.web.DomainController#getObjectById(java.lang.Long)
	 */
	@Override
	protected PersistableDomain getObjectById(Long id) {
		return (Environment) Environment.getById(id, Environment.class);
	}

	/**
	 * @see com.qachecklist.web.DomainController#getObjectList()
	 */
	@Override
	protected List<? extends PersistableDomain> getObjectList() {
		return Check.getList(Check.class);
	}

	/**
	 * @see com.qachecklist.web.DomainController#getObjectListAttributeName()
	 */
	@Override
	protected String getObjectListAttributeName() {
		return listAttributeName;
	}
	
	/**
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	@Override
	protected void handleCreateAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		List<? extends PersistableDomain> itemList = Item.getList(Item.class);
		List<? extends PersistableDomain> envList = Environment.getList(Environment.class);
		request.setAttribute("items", itemList);
		request.setAttribute("environments", envList);
		super.handleCreateAction(request, response);
	}

}
